package com.googlecode.c4e.ui.views.internal;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.model.IWorkbenchAdapter;

import com.googlecode.c4e.api.Registry;
import com.googlecode.c4e.api.model.Project;
import com.googlecode.c4e.ui.ContinuumPlugin;

public class ProjectAdapter implements IWorkbenchAdapter {

	public Object[] getChildren(Object obj) {
		return new Object[0];
	}

	public ImageDescriptor getImageDescriptor(Object obj) {
		Project project = (Project) obj;
		Integer state = project.getState();
		if (state == null) {
			try {
				state = Registry.getDefault().checkProjectState(project);
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		project.setState(state);
		return ContinuumPlugin.getDefault().getImageDescriptorForProjectState(
				state);
	}

	public String getLabel(Object obj) {
		Project project = (Project) obj;
		return project.getName();
	}

	public Object getParent(Object obj) {
		Project project = (Project) obj;
		return project.getGroup();
	}

}
